//
//  TopImageViewAndBottomLabelView.m
//  333333
//
//  Created by 刘应平 on 2017/8/31.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "TopImageViewAndBottomLabelView.h"

@implementation TopImageViewAndBottomLabelView

/**  80  */
- (instancetype)initWithFrame:(CGRect)frame count:(NSInteger)count
{
    self = [super initWithFrame:frame];
    if (self) {
        
        CGFloat with = [UIScreen mainScreen].bounds.size.width / count;
        
        
        [self addSubview:self.topImageView];
        self.topImageView.sd_layout
        .topSpaceToView(self,10 * [UIScreen zj_screenHScale])
        .heightIs(50 * [UIScreen zj_screenHScale])
        .widthIs(50 * [UIScreen zj_screenHScale])
        .centerXEqualToView(self);
        
        
        [self addSubview:self.bottomLabel];
        self.bottomLabel.sd_layout
        .topSpaceToView(self.topImageView,8 * [UIScreen zj_screenHScale])
        .widthIs(with)
        .heightIs(12 * [UIScreen zj_screenHScale])
        .leftEqualToView(self);
        
        
        
        [self addSubview: self.messageNumber];
        self.messageNumber.sd_layout
        .topSpaceToView(self, 8 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.topImageView, -1 * [UIScreen zj_screenWScale])
        .heightIs(20 * [UIScreen zj_screenWScale])
        .widthIs(20 * [UIScreen zj_screenWScale]);
        self.messageNumber.hidden = YES;
        
        
     
        [self addSubview: self.redView];
        self.redView.sd_layout
        .topSpaceToView(self, 8 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.topImageView, -3 * [UIScreen zj_screenWScale])
        .heightIs(10 * [UIScreen zj_screenWScale]).widthIs(10 * [UIScreen zj_screenWScale]);
        self.redView.hidden = YES;
        
        
        
    }
    return self;
}

- (UILabel *)bottomLabel{
    if (!_bottomLabel) {
        _bottomLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor blackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font =[UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _bottomLabel;
}


- (UILabel *)messageNumber{
    if (!_messageNumber) {
        _messageNumber = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor whiteColor];
            label.backgroundColor = [UIColor redColor];
            label.font =[UIFont systemFontOfSize:10 * [UIScreen zj_textFontScale]];
            label.layer.cornerRadius = 10 * [UIScreen zj_screenWScale];
            label.layer.masksToBounds = YES;
            label.text = @"99+";
            label;
        });
    }
    return _messageNumber;
}

- (UIView *)redView{
    if (_redView == nil) {
        _redView = [UIView new];
        _redView.backgroundColor = [UIColor zj_colorWithHexString:@"f24141"];
        _redView.layer.cornerRadius = 5 * [UIScreen zj_screenWScale];
        _redView.layer.masksToBounds = YES;
    }
    return _redView;
}

- (UIImageView *)topImageView{
    if (_topImageView == nil) {
        _topImageView = [UIImageView new];
        _topImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _topImageView;
}
@end
